<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Lookup a message in the current domain</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.gettext" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">gettext</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">gettext</span> &mdash; <span class="dc-title">Lookup a message in the current domain</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.gettext-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>gettext</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code></span>
   ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Looks up a message in the current domain.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.gettext-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">message</code></dt>

     <dd>

      <p class="para">
       The message being translated.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.gettext-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a translated <span class="type"><a href="language.types.string.html" class="type string">string</a></span> if one is found in the 
   translation table, or the submitted message if not found.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.gettext-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2887">
    <p><strong>Example #1 <span class="function"><strong>gettext()</strong></span>-check</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Set&nbsp;language&nbsp;to&nbsp;German<br /></span><span style="color: #0000BB">putenv</span><span style="color: #007700">(</span><span style="color: #DD0000">'LC_ALL=de_DE'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Specify&nbsp;location&nbsp;of&nbsp;translation&nbsp;tables<br /></span><span style="color: #0000BB">bindtextdomain</span><span style="color: #007700">(</span><span style="color: #DD0000">"myPHPApp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"./locale"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Choose&nbsp;domain<br /></span><span style="color: #0000BB">textdomain</span><span style="color: #007700">(</span><span style="color: #DD0000">"myPHPApp"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Translation&nbsp;is&nbsp;looking&nbsp;for&nbsp;in&nbsp;./locale/de_DE/LC_MESSAGES/myPHPApp.mo&nbsp;now<br /><br />//&nbsp;Print&nbsp;a&nbsp;test&nbsp;message<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">gettext</span><span style="color: #007700">(</span><span style="color: #DD0000">"Welcome&nbsp;to&nbsp;My&nbsp;PHP&nbsp;Application"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Or&nbsp;use&nbsp;the&nbsp;alias&nbsp;_()&nbsp;for&nbsp;gettext()<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">_</span><span style="color: #007700">(</span><span style="color: #DD0000">"Have&nbsp;a&nbsp;nice&nbsp;day"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>
 

 <div class="refsect1 notes" id="refsect1-function.gettext-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    You may use the underscore character &#039;_&#039; as an alias to this function.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Setting a language isn&#039;t enough for some systems and the 
    <span class="function"><a href="putenv.html" class="function">putenv()</a></span> should be used to define the 
    current locale.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.gettext-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="setlocale.html" class="function" rel="rdfs-seeAlso">setlocale()</a> - 设置地区信息</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>